#!/usr/bin/python
# -*- coding: UTF-8 -*-

#~ A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
#~ 
#~ Find the largest palindrome made from the product of two 3-digit numbers.
#~ TODO : NOT SOLVED

import time
start = time.clock()

def is_palyndromic( n ):
  string = str( n )
  count = len(string)
  k=0
  while ( k < count/2 ):
    if ( string[k] != string[count-1-k] ):
      return False
    #~ else :
      #~ print string+" > "+string[k]+" == "+string[count-1-k]
    k+=1
  return True

print is_palyndromic( 918719 )


x = 999
y = 999
p = x * y
result = 0
paly = []

print p

while ( p > 99 * 99 ) :
  p-=1
  if ( is_palyndromic(p) ):
    paly.append(p)



for p in paly :
  k=1
  while ( k < 1000 ):
    if ( p%k == 0 and 99 < p/k and p/k < 1000 and p > result ):
      result = p
      print result
      break
    k+=1


print "problem solved in ", (time.clock() - start), "s"
